package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.enums.DelFlag;
import com.ruoyi.system.domain.ShouCang;
import com.ruoyi.system.mapper.ShouCangMapper;
import com.ruoyi.system.service.IShouCangService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 订单详情信息 服务实现类
 * </p>
 *
 * @author qubaofeng
 * @since 2025-02-16
 */
@Service
public class ShouCangServiceImpl extends ServiceImpl<ShouCangMapper, ShouCang> implements IShouCangService {

    @Override
    public boolean removeShouCang(ShouCang shouCang) {

        LambdaQueryWrapper<ShouCang> update = new LambdaQueryWrapper<>();
        update.eq(ShouCang::getUserId, shouCang.getUserId());
        update.eq(ShouCang::getHuoPinId, shouCang.getHuoPinId());

        int row = baseMapper.update(shouCang, update);
        return row>0;
    }

    @Override
    public boolean saveShouCang(ShouCang shouCang) {
        LambdaQueryWrapper<ShouCang> update = new LambdaQueryWrapper<>();
        update.eq(ShouCang::getUserId, shouCang.getUserId());
        update.eq(ShouCang::getHuoPinId, shouCang.getHuoPinId());
        update.eq(ShouCang::getDelFlag, DelFlag.NOMAL.getCode());

        ShouCang data = baseMapper.selectOne(update, false);
        if(data !=null){
            return true;
        } else {
            return baseMapper.insert(shouCang) > 0;
        }
    }
}
